<template>
	<div class="page">
		<div class="p-10 system-page-background b-radius-4">
			<my-form
				inline
				query
				label-width="70px"
				:model="queryParams"
				:formItem="[
					{ prop: 'likeJobCode', label: '任务编号' },
					{ prop: 'likeJobName', label: '任务名称' },
					{ prop: 'likeJobGroup', label: '任务分组' },
					{
						itemType: 'select',
						list: Tasklist,
						prop: 'invokeTarget',
						label: '任务目标'
					},
					{
						itemType: 'select',
						list: statusList,
						prop: 'status',
						label: '执行状态'
					}
				]"
				:searchFn="() => refTable.reload()"
			/>
		</div>
		<div class="flex-auto flex-col m-t-10 system-page-background b-radius-4">
			<div class="p-10" v-hasPermi="['']">
				<my-button-export :load="exportFn" :disabled="!state.list.length" v-hasPermi="['']" />
				<el-button type="danger" :disabled="!tableSelection.length" @click.prevent="deleteFn(tableSelection)" icon="Delete" v-hasPermi="['']">
					删除
				</el-button>
			</div>
			<my-list-panel ref="refTable" :loadFn="loadData" :total="state.total">
				<template #default="{ page, size }">
					<my-table :data="state.list" :columns="state.columns" @selection-change="(val) => (tableSelection = val)">
						<template #index="{ $index }">
							{{ $index + 1 + (page - 1) * size }}
						</template>
					</my-table>
				</template>
			</my-list-panel>
		</div>
	</div>
</template>

<script setup name="logininfor">
import { listJobTask, pageJoblog as page, removeJoblog as remove, exportJoblog } from '@a/system';
import { downloadBlob } from '@u/download';

const columns = [
	{
		type: 'selection'
	},
	{
		label: '序号',
		width: '80',
		prop: 'index'
	},
	{
		label: '任务编号',
		prop: 'jobCode'
	},
	{
		label: '任务名称',
		prop: 'jobName'
	},
	{
		prop: 'jobGroup',
		label: '任务分组'
	},
	{
		label: '任务目标',
		prop: 'invokeTarget',
		formatter: (row) => selectDictLabel(Tasklist.value, row.invokeTarget)
	},
	{
		label: '执行表达式',
		prop: 'cronExpression'
	},
	{
		label: '执行状态',
		prop: 'status',
		formatter: (row) => selectDictLabel(statusList, row.status)
	},
	{
		label: '异常信息',
		prop: 'exceptionInfo'
	},
	{
		label: '开始时间',
		prop: 'startTime',
		width: 180
	},
	{
		label: '结束时间',
		prop: 'endTime',
		width: 180
	}
];
const api = { page, remove };

const { queryParams, refTable, tableSelection, loadData, deleteFn } = pageMixin({
	columns,
	api
});

/******************************************************************* 导出按钮操作 ******************************************************************/
function exportFn() {
	return exportJoblog(queryParams.value).then((data) => {
		downloadBlob(data, '定时任务日志.xlsx');
	});
}

const statusList = [
	{ dictLabel: '成功', dictValue: 0 },
	{ dictLabel: '失败', dictValue: 1 }
];

/*****************************************************************任务目标数据**************************************************************/
const Tasklist = ref([]);
listJobTask().then((res) => {
	Tasklist.value = res.data.map((item) => ({
		dictLabel: item.label,
		dictValue: item.value
	}));
});
</script>
